package com.cnebula.dataprocess.task.center.comsumer;

import org.apache.rocketmq.spring.starter.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.starter.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cnebula.dataprocess.task.center.MainTask;
import com.cnebula.dataprocess.task.center.message.MainTaskMessage;
import com.cnebula.dataprocess.task.center.scheduler.TaskScheduler;
import com.cnebula.dataprocess.task.center.service.TaskService;
import com.google.gson.Gson;

@Service
@RocketMQMessageListener(topic = "mysql_task_new", consumerGroup = "mysql_task_consumer_group_new")
public class MainTaskConsumer implements RocketMQListener<MainTaskMessage> {
	
	private static final Logger log = LoggerFactory.getLogger(MainTaskConsumer.class);

	private Gson gson = new Gson();
	

	@Autowired
	TaskService taskService;

	@Autowired
	TaskScheduler taskScheduler;

	@Override
	public void onMessage(MainTaskMessage arg0) {
		
		log.info("=============================receive main task message=============================");
		log.info(gson.toJson(arg0));
		log.info("===================================================================================");
		
		MainTask mainTask = taskService.createMainTask(arg0);
		taskScheduler.submitMainTask(mainTask);
	}

}
